package org.example.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.mapper.UserMapper;
import org.example.entity.User;
import org.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private UserMapper userMapper;


    @Override
    public int register(User user) {
        return userMapper.insert(user);
    }

    @Override
    public User login(User user) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();//条件构造器
        wrapper.eq("phone",user.getPhone());//设置条件

        return userMapper.selectOne(wrapper);//查询
    }

    @Override
    public int tx(User user) {
        UpdateWrapper wrapper=new UpdateWrapper<>();//条件构造器
        wrapper.eq("phone",user.getPhone());//设置条件
        return userMapper.update(user,wrapper);//更新
    }

    //根据用户id查询信息
    @Override
    public User selectById(int id) {
        return userMapper.selectById(id);
    }

    //根据用户id修改信息
    @Override
    public int updateUserByUsername(User user) {
        return userMapper.updateUserByUsername(user);
    }
}
